#ifndef GND_SESSION_H
#define GND_SESSION_H

#include <gtk/gtk.h>
//#include "gndmodule.h"

//前向声明，防止头文件循环引用
//struct _GndConnect;
typedef struct _GndConnect GndConnect;
//struct _GndModule;
typedef struct _GndModule GndModule;

typedef enum _GndSessionStatus
{
    GND_SESSION_STATUS_SUCCEED,
    GND_SESSION_STATUS_FAILURE
} GndSessionStatus;

typedef struct _GndSession{
    GSocket * socket;
    GndModule * module;
    GndConnect * connect;

    GRecMutex * mutex_socket;
} GndSession;

typedef struct _GndSessionData {
    GndSession * session;
    gint32 len;
    char * data;
    GndSessionStatus status;
    gpointer other_data;
    GFunc other_func;
} GndSessionData;

GndSession * gnd_session_new(GndModule * module);
gboolean gnd_session_free(GndSession * session);

gboolean gnd_session_connect_finished_cb(GSocket * socket, GIOCondition condition, GndSession * self);
gboolean gnd_session_data_arrive_cb(GSocket * socket, GIOCondition condition, GndSession * self);

gboolean gnd_session_send_data(GndSession * self, gchar * data, int len);
gboolean gnd_session_accept_data(GndSession * self,
                                 guint timeout,
                                 GSourceFunc callback);
gboolean gnd_session_close(GndSession * self);
gboolean gnd_session_isclosed(GndSession * self);
#endif
